package com.activemq.controller;

import com.activemq.R;
import com.activemq.service.ProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;

/**
 * 模拟微信支付回调
 */
@RestController
@RequestMapping("/api/v1")
public class TestController {

    @Value("queueName")
    private String queueName;
    @Autowired
    private Queue queue;
    @Autowired
    private ProducerService producerService;

    //========================== 点对点模式 ==============================
    /**
     * 模拟微信支付回调
     * @param msg
     * @return
     */
    @GetMapping("/order")
    public R<String> order(String msg){
        System.out.println("发送的消息："+msg);
        //Destination destination = new ActiveMQQueue(queueName);
        producerService.sendMessage(queue,msg);
        return R.ok();
    }

    /*@JmsListener(destination = "test.queue")
    public void reciveQueue(String text){
        System.out.println("接收到的消息："+text);
    }*/

    //========================== 发布订阅模式 ==============================
    /**
     * 模拟微信支付回调
     * @param msg
     * @return
     */
    @GetMapping("/topic")
    public R<String> topic(String msg){
        System.out.println("topic发送的消息："+msg);
        producerService.publish(msg);
        return R.ok();
    }
}
